//
// Copyright (c) 2009-2011, chunquedong
//
// This file is part of ChunMap project
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
//
// History:
//   2011-05-03  Jed Young  Creation
//

using gfx
using gfx2

using chunmapModel
using chunmapData
using chunmapRaster

**
** General Symbolizer
**
@Js
const class GeneralSym : Symbolizer
{
  const RasterSym rasterSym := RasterSym{}
  const SimplePointSym pointSym := SimplePointSym{}
  const SimpleLineSym lineSym := SimpleLineSym{}
  const SimplePolygonSym polygonSym := SimplePolygonSym{}

  new make(|This| f) { f(this) }

  override Void draw(RenderEnv r)
  {
    if(r.data is Shape)
    {
      Shape shape := r.data
      drawGeometry(shape.geometry, r)
    }
    else if(r.data is Raster)
    {
      rasterSym.draw(r)
    }
  }

//////////////////////////////////////////////////////////////////////////
// Draw Geometry
//////////////////////////////////////////////////////////////////////////

  private Void drawGeometry(Geometry geo, RenderEnv r) { selectDraw(geo, r) }

  private Void selectDraw(Geometry geo, RenderEnv r)
  {
    if (geo is GeoPoint) pointSym.drawGeometry(geo, r)
    else if (geo is LineString) lineSym.drawGeometry(geo, r)
    else if (geo is Polygon) polygonSym.drawGeometry(geo, r)
    else if (geo is GeometryCollection)
    {
      GeometryCollection geoCollection := geo
      geoCollection.each { drawGeometry(it, r) }
    }
    else throw UnsupportedErr()
  }
}